package main

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"fmt"
	"strconv"
)

var engine *xorm.Engine

type Userinfo struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

func main() {
	var err error
	engine, err = xorm.NewEngine("mysql", "kingshard:kingshard@tcp(127.0.0.1:9696)/test?charset=utf8&interpolateParams=true")
	if err != nil {
		fmt.Println(err)
	}

	res, err := engine.Exec("delete from `userinfo`")
	fmt.Println(res)
	if err != nil {
		fmt.Println(err)
	}

	for i := 1; i <=1000; i++ {
		user := new(Userinfo)
		user.Id = i
		user.Name = "myname" + strconv.Itoa(i)

		affected, err := engine.Insert(user)
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(affected)
	}

	everyone := make([]Userinfo, 0)
	err = engine.Find(&everyone)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(len(everyone))
	fmt.Println(everyone)

}
